package com.rrd.itext.html;

import com.rrd.itext.utils.color.ColorUtil;

//htmlUtil
public final class ITextServiceHtmlUtil
{
	public static float[] RGBToCMYK(String value){
	    int colorR = 0;
	    int colorG = 0;
	    int colorB = 0;
	    if(value == null){
	        value = "";
	    }
	    if(value.contains("rgb") || value.contains("RGB")){
            String subStr = value.substring(value.indexOf("(") + 1, value.indexOf(")"));
            String[] rgbColors = subStr.split(",");
            colorR = Integer.parseInt(rgbColors[0]);
            colorG = Integer.parseInt(rgbColors[1]);
            colorB = Integer.parseInt(rgbColors[2]);
	    }else if(value.contains("#")){
	        String color = value.substring(value.indexOf("#") + 1);
	        if(color.length() == 6){
	            colorR = Integer.valueOf(color.substring(0,2),16);
	            colorG = Integer.valueOf(color.substring(2,4),16);
	            colorB = Integer.valueOf(color.substring(4,6),16);
	        }else if(color.length() == 3){
	            colorR = Integer.valueOf(color.substring(0,1)+color.substring(0,1),16);
                colorG = Integer.valueOf(color.substring(1,2)+color.substring(1,2),16);
                colorB = Integer.valueOf(color.substring(2,3)+color.substring(2,3),16);
	        }
	    }else{
	        if("black".equalsIgnoreCase(value)){
	            colorR = 0;
	            colorG = 0;
	            colorB = 0;
	        }else if("red".equalsIgnoreCase(value)){
                colorR = 255;
                colorG = 0;
                colorB = 0;
            }else if("blue".equalsIgnoreCase(value)){
                colorR = 0;
                colorG = 0;
                colorB = 255;
            }else if("white".equalsIgnoreCase(value)){
                colorR = 255;
                colorG = 255;
                colorB = 255;
            }
	    }
		return ColorUtil.getInstance().RGB2CMYK(colorR, colorG, colorB);
    }
}
